package com.twp.auth.domain.authority.user;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.twp.auth.domain.authority.Role;
import lombok.*;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;

@EqualsAndHashCode(
        exclude = {
                "roleList","detail"
        }
)
@ToString(
        exclude = {
                "roleList","detail"
        }
)
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
@Table(
        name = "twp_manage_user",
        indexes = {
                @Index(name = "userName_index",columnList = "userName"),
                @Index(name = "name_index",columnList = "name"),
        },
        uniqueConstraints ={
                @UniqueConstraint(
                        columnNames = {"userName"}
                ),
                @UniqueConstraint(
                        columnNames = {"name"}
                )
        }
)
public class ManageUser {
    /**
     * 管理员编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    /**
     * 管理员工号
     */
    @Column(name = "userName",unique = true)
    private String userName;
    /**
     * 管理员姓名
     */
    private String name;

    private String sex;

    /**
     * 密码
     */
    @Column(nullable = false)
    private String password;

    /**
     * 用户状态1有效0无效
     */
    private Integer status;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "updateTime")
    private Date updateTime;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "createTime")
    private Date createTime;

    @Transient
    private String roleIds;

    @OneToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "manageUser")
    private UserDetail detail;

    @JsonIgnore
    @ManyToMany(mappedBy = "manageUserList",fetch = FetchType.EAGER)
    private List<Role> roleList;

}
